<template>
  <div>
    <div class="swipper">
      <van-search show-action placeholder="请输入搜索关键词">
        <template #label>
          <span @click="$router.push('/address')">{{
            $route.params.label
          }}</span>
        </template>
        <template #action>
          <van-icon name="location-o" size="20" color="#fff" />
        </template>
      </van-search>
      <van-swipe :autoplay="3000">
        <van-swipe-item v-for="(item, index) in images" :key="index">
          <img v-lazy="item" />
        </van-swipe-item>
      </van-swipe>
    </div>

    <van-grid :border="false" :column-num="4" class="icon">
      <van-grid-item>
        <div class="grid">
          <van-icon name="home-o" size="2.5rem" color="#353755" />
        </div>
        <p>整租</p>
      </van-grid-item>
      <van-grid-item>
        <div class="grid">
          <van-icon name="friends-o" size="2.5rem" />
        </div>
        <p>合租</p>
      </van-grid-item>
      <van-grid-item>
        <div class="grid">
          <van-icon name="location-o" size="2.5rem" />
        </div>
        <p>地图找房</p>
      </van-grid-item>
      <van-grid-item>
        <div class="grid">
          <van-icon name="wap-home-o" size="2.5rem" />
        </div>
        <p>去出租</p>
      </van-grid-item>
    </van-grid>

    <div class="zufang">
      <div class="top">
        <h4>租房小组</h4>
        <span>更多</span>
      </div>
      <div class="hot">
        <div class="box" v-for="item in groups" :key="item.id">
          <div class="left">
            <img :src="item.imgSrc" alt="" />
          </div>
          <div class="right">
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { swiper, groups } from '@/api/home'
export default {
  async created() {
    const { body } = await swiper()
    this.images = body.map((item) => 'http://liufusong.top:8080' + item.imgSrc)

    const { body: group } = await groups()
    this.groups = group.map((item) => {
      return {
        id: item.id,
        desc: item.desc,
        title: item.title,
        imgSrc: 'http://liufusong.top:8080' + item.imgSrc
      }
    })
  },
  data() {
    return {
      images: [],
      groups: []
    }
  }
}
</script>

<style scoped lang="less">
.swipper {
  position: relative;
  height: 212px;
  width: 100%;
  .van-search--show-action {
    position: absolute;
    width: 100%;
    margin-top: 15px;
    background-color: transparent;
    z-index: 1;
  }
  img {
    width: 100%;
    height: 212px;
  }
}
.icon {
  height: 122px;
  p {
    margin-top: 10px;
    font-size: 14px;
  }
}
.zufang {
  padding: 0 10px;
  background: #e0e4ee;
  overflow: hidden;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 18px;
    margin: 15px 0 15px 10px;
    span {
      color: rgb(174, 162, 162);
      font-size: 14px;
    }
  }
  ::v-deep .van-grid-item__content {
    height: 60px;
  }
  .hot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .box {
      display: flex;
      width: 172px;
      height: 60px;
      margin-bottom: 10px;
      background: #fff;
      border-radius: 3px;
      .left {
        height: 60px;
        width: 60px;
        line-height: 60px;
        text-align: center;
        img {
          width: 70%;
          height: 70%;
        }
      }
      .right {
        display: flex;
        flex-direction: column;
        justify-content: center;
        font-size: 14px;
      }
    }
  }
}
::v-deep .van-grid-item__content {
  padding: 0;
}
.grid {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: #e0e4ee;
}

.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
</style>
